# # 实例一
# from enum import Enum
#
# class Operation(Enum):
#     INCREMENT = 1
#     DECREMENT = 2
#
# class B:
#     def execute(self, operation: Operation, value: int) -> int:
#         if operation == Operation.INCREMENT:
#             return value + 1
#         elif operation == Operation.DECREMENT:
#             return value - 1
#         else:
#             raise ValueError("Unknown operation")
#
# class A:
#     def process(self, initial_value: int) -> int:
#         b = B()
#         # 调用B类的execute方法，并传递控制变量
#         incremented_value = b.execute(Operation.INCREMENT, initial_value)
#         decremented_value = b.execute(Operation.DECREMENT, incremented_value)
#         return decremented_value
#
# a = A()
# result = a.process(5)
# print(result)

# 实例二
class B:
    def execute(self, operation_code: int, value: int) -> int:
        if operation_code == 1:
            return value + 1
        elif operation_code == 2:
            return value - 1
        else:
            raise ValueError("Unknown operation code")

class A:
    def process(self, initial_value: int) -> int:
        b = B()
        # 调用B类的execute方法，并传递控制变量（含义不清晰）
        incremented_value = b.execute(1, initial_value)  # 这里的1没有清晰的语义
        decremented_value = b.execute(2, incremented_value)  # 这里的2也没有清晰的语义
        return decremented_value

a = A()
result = a.process(5)
print(result)
